﻿using System;
using System.Collections.Generic;

namespace DemoService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "CustomersService" in code, svc and config file together.
    public class CustomersService : ICustomersService
    {
        private static List<Customer> _customers;

        static CustomersService()
        {
            _customers = new List<Customer>
                                                        {
                                                            new Customer
                                                                {
                                                                    CustomerId = Guid.NewGuid(),
                                                                    FirstName = "AAA",
                                                                    LastName = "BBB",
                                                                    PhoneNumber = "123123"
                                                                },
                                                            new Customer
                                                                {
                                                                    CustomerId = Guid.NewGuid(),
                                                                    FirstName = "BAD",
                                                                    LastName = "CCC",
                                                                    PhoneNumber = "123"
                                                                },
                                                            new Customer
                                                                {
                                                                    CustomerId = Guid.NewGuid(),
                                                                    FirstName = "CAF",
                                                                    LastName = "KKK",
                                                                    PhoneNumber = "1245623"
                                                                },
                                                            new Customer
                                                                {
                                                                    CustomerId = Guid.NewGuid(),
                                                                    FirstName = "DAH",
                                                                    LastName = "SSS",
                                                                    PhoneNumber = "125463"
                                                                },
                                                            new Customer
                                                                {
                                                                    CustomerId = Guid.NewGuid(),
                                                                    FirstName = "EAU",
                                                                    LastName = "RRR",
                                                                    PhoneNumber = "1256"
                                                                },
                                                        };
        }

        public CustomersService()
        {
        }

        #region ICustomersService Members

        public Customer[] GetCustomers()
        {
            return _customers.ToArray();
        }

        public void InsertCustomer(Customer customer)
        {
            _customers.Add(customer);
        }

        public void RemoveCustomer(Customer customer)
        {
            _customers.Remove(customer);
        }

        public void UpdateCustomer(Customer customer)
        {
            int index = _customers.FindIndex(currentCustomer => (currentCustomer.Equals(customer)));
            _customers[index] = customer;
        }

        #endregion
    }
}